﻿<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
	namespace="Buaya.Model" assembly="Buaya.Core">
	
	<class name="User" table="users">
		<id name="Id">
			<generator class="native"/>
		</id>
		<property name="Name"/>
		<property name="Password" column="Pass"/>
		<bag name="Modules" inverse="true" cascade="all-delete-orphan" order-by="PlacementOrder">
			<key column="UserId"/>
			<one-to-many class="UserModule"/>
		</bag>
	</class>

	<class name="UserModule" table="user_modules">
		<id name="Id">
			<generator class="native"/>
		</id>
	    	<many-to-one name="User" class="User" column="UserId"/>
	    	<many-to-one name="Module" class="Module" column="ModuleId"/>
		<property name="Order" column="PlacementOrder"/>
		<bag name="Commands" inverse="true" cascade="all-delete-orphan">
			<key column="ModuleId"/>
			<one-to-many class="UserModuleCommand"/>
		</bag>
	</class>

	<class name="UserModuleCommand" table="user_module_commands">
		<id name="Id">
			<generator class="native"/>
		</id>
	    	<many-to-one name="Module" class="UserModule" column="ModuleId"/>
	    	<many-to-one name="ModuleCommand" class="ModuleCommand" column="ModuleCommandId"/>
	</class>

</hibernate-mapping>
